//
//  TYHUserCenterCell.m
//  OpenPractice
//
//  Created by 谭月红 on 2018/12/30.
//  Copyright © 2018  lijinghua. All rights reserved.
//

#import "TYHUserCenterCell.h"

@implementation TYHUserCenterCell

+ (instancetype)cellWithtableView:(UITableView *)tableView {
    static NSString *resusedId = @"TYHUSercentCellId";
    TYHUserCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:resusedId];
    if (!cell) {
        cell = [[TYHUserCenterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resusedId];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initAllSubViews];
    }
    return self;
}

- (void)initAllSubViews {
    UIImageView *iconImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    
    UILabel *titleLable = [[UILabel alloc] init];
    [self.contentView addSubview:titleLable];
    self.titleLabel = titleLable;
    
    UILabel *subTileLable = [[UILabel alloc] init];
    [self.contentView addSubview:subTileLable];
    self.subTitleLabel = subTileLable;
    
    UIView *botomlive = [[UIView alloc] init];
    [self.contentView addSubview:botomlive];
    self.bottomLine = botomlive;
    
    UIImageView *accessImage = [[UIImageView alloc] init];
    [self.contentView addSubview:accessImage];
    accessImage.image = [UIImage imageNamed:@"common_arrow"];
    self.accessImageView = accessImage;
    
    UIView *speateView = [[UIView alloc] init];
    speateView.backgroundColor = kOPSeparateBackgroundColor;
    [self.contentView addSubview:speateView];
    self.spreateView = speateView;
}

- (void)setDataModel:(NSDictionary *)model {
    NSString *title = [model objectForKey:@"title"];
    if (title.length>0) {
        self.titleLabel.hidden = NO;
        self.titleLabel.text = title;
    } else {
        self.titleLabel.hidden = YES;
    }
    NSString *suTile = [model objectForKey:@"subTitle"];
    if (suTile.length>0) {
        self.subTitleLabel.hidden = NO;
        self.subTitleLabel.text = suTile;
    } else {
        self.subTitleLabel.hidden = YES;
    }
    
    NSString *iconName = [model objectForKey:@"mainIcon"];
    if (iconName.length>0) {
        self.iconImageView.hidden = NO;
        self.iconImageView.image = [UIImage imageNamed:iconName];
    } else {
        self.iconImageView.hidden = YES;
    }
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.iconImageView.frame = CGRectMake(14, 8, 22, 22);
    self.titleLabel.frame = CGRectMake(self.iconImageView.right+13, 0, 60, self.height);
    self.accessImageView.frame = CGRectMake(self.width-15-5, (self.height-10)/2, 5, 10);
    self.subTitleLabel.frame = CGRectMake(self.titleLabel.right+5, 0, self.accessImageView.left-5-self.titleLabel.right-5, self.height);
    self.spreateView.frame = CGRectMake(20, self.height-kTYHSingleLine, self.width-20, kTYHSingleLine);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
